﻿using PersonalWeb.Client.Pages;
using PersonalWeb.Components;

namespace PersonalWeb
{
    public class Program
    {
        public static string address = string.Empty;
        public static string appPath = string.Empty;
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.
            builder.Services.AddRazorComponents()
                .AddInteractiveWebAssemblyComponents();

            address = builder.Configuration.GetValue<string>("Kestrel:Endpoints:Http:Url") ?? "http://localhost/";
            string? path = builder.Configuration.GetValue<string>("AppPath");
            if (!string.IsNullOrEmpty(path))
            {
                appPath = path;
            }
            else
            {
                appPath = "C:\\Users\\Administrator\\FTP\\PC\\程序";
            }

            builder.Services.AddControllers();
            builder.Services.AddHttpClient();
            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            app.UseAntiforgery();

            app.MapRazorComponents<App>()
                .AddInteractiveWebAssemblyRenderMode()
                .AddAdditionalAssemblies(typeof(Client._Imports).Assembly);

            app.MapControllers(); // 添加控制器

            app.Run();
        }
    }
}
